export function timeCycle(value, type) {
	if (value) {
		var dd = new Date(value * 1000);
		var y = dd.getFullYear();
		var m = dd.getMonth() + 1;
		var d = dd.getDate();
		var h = dd.getHours();
		var i = dd.getMinutes();
		var s = dd.getSeconds();
		m = m < 10 ? '0' + m : m;
		d = d < 10 ? '0' + d : d;
		h = h < 10 ? '0' + h : h;
		i = i < 10 ? '0' + i : i;
		s = s < 10 ? '0' + s : s;
		if (type == 1) {
			return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s
		} else if (type == 2) {
			return y + '-' + m + '-' + d + ' ' + h + ':' + i
		} else if (type == 3) {
			return m + '/' + d
		}  else if (type == 4) {
			return y + '.' + m + '.' + d
		} else {
			return y + '-' + m + '-' + d
		}
	}
}
export function handleTime(value, type = 1) {
	if (value) {
		let time = Number(value);
		let h = time / 3600 < 10 ? "0" + parseInt(time / 3600) : parseInt(time / 3600);
		if (h != '00') time = time - h * 3600;
		let m = time / 60 < 10 ? "0" + parseInt(time / 60) : parseInt(time / 60);
		let s = time % 60 < 10 ? "0" + (time % 60) : time % 60;
		if (type == 1) {
			if (h == '00') {
				return m + ":" + s;
			} else {
				return h + ':' + m + ":" + s;
			}
		} else if (type == 2) {
			return m + ":" + s;
		}
	}
}
export function timeFrom(timestamp = null, format = 'yyyy-mm-dd') {
	if (timestamp == null) timestamp = Number(new Date());
	timestamp = parseInt(timestamp);
	// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
	if (timestamp.toString().length == 10) timestamp *= 1000;
	var timer = (new Date()).getTime() - timestamp;
	timer = parseInt(timer / 1000);
	// 如果小于5分钟,则返回"刚刚",其他以此类推
	let tips = '';
	switch (true) {
		case timer < 300:
			tips = '刚刚';
			break;
		case timer >= 300 && timer < 3600:
			tips = parseInt(timer / 60) + '分钟前';
			break;
		case timer >= 3600 && timer < 86400:
			tips = parseInt(timer / 3600) + '小时前';
			break;
		case timer >= 86400 && timer < 2592000:
			tips = parseInt(timer / 86400) + '天前';
			break;
		default:
			// 如果format为false，则无论什么时间戳，都显示xx之前
			if (format === false) {
				if (timer >= 2592000 && timer < 365 * 86400) {
					tips = parseInt(timer / (86400 * 30)) + '个月前';
				} else {
					tips = parseInt(timer / (86400 * 365)) + '年前';
				}
			} else {
				tips = timeFormat(timestamp, format);
			}
	}
	return tips;
}
export function handleMTH(timestamp = null) {
	if (timestamp == 0 || timestamp == '') return ' ';
	if (timestamp == null) timestamp = Number(new Date());
	timestamp = parseInt(timestamp);
	let h = timestamp / 3600 / 24;
	return (Math.floor(h * 100)) / 100
}
export function handleQz(timestamp) {
	if (timestamp == 0) return ' ';
	return Number(timestamp).toFixed(0)
}
export function handleZm(val) {
	if(val==0){
		return 'A'
	}else if(val==1){
		return 'B'
	}else if(val==2){
		return 'C'
	}else if(val==3){
		return 'D'
	}
}
export function handleNum(num) {
	let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; //changeNum[0] = "零"
	let unit = ["", "十", "百", "千", "万"];
	num = parseInt(num);
	let getWan = (temp) => {
		let strArr = temp.toString().split("").reverse();
		let newNum = "";
		for (var i = 0; i < strArr.length; i++) {
			newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" :
				changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
		}
		return newNum;
	}
	let overWan = Math.floor(num / 10000);
	let noWan = num % 10000;
	if (noWan.toString().length < 4) noWan = "0" + noWan;
	return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
}